package com.le.tester.javaThink.fifth.chapter18_Str;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * createTime：2021/8/13 17:02
 * description：TheReplacements
 */
public class TheReplacements {
    public static void main(String[] args) throws IOException {
        String s = Files.lines(Paths.get("TheReplacements.java")).collect(Collectors.joining("\n"));

        Matcher input = Pattern.compile("/\\*!(.*)!\\*/", Pattern.DOTALL).matcher(s);

        if (input.find()) {
            s = input.group(1);
        }
        s = s.replaceAll(" {2,}", " ");
        s = s.replaceAll("(?m)^ +", "");

        System.out.println(s);

        s = s.replaceFirst("[aeiou]", "(VOWEL1)");
        StringBuffer stringBuffer = new StringBuffer();
        Pattern pattern = Pattern.compile("[aeiou]");
        Matcher matcher = pattern.matcher(s);
        while (matcher.find()) {
            matcher.appendReplacement(stringBuffer, matcher.group().toUpperCase());
        }
        matcher.appendTail(stringBuffer);
        System.out.println(stringBuffer);
    }
}
